﻿Imports IControl.IControls
Imports DevExpress.XtraEditors
Imports DevExpress.LookAndFeel
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraLayout
Imports System.Drawing
Imports DevExpress.XtraEditors.Repository
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Imports DevExpress.Utils
Imports System.ComponentModel

Public Class IFormDoi
    Private m_TaoMoi, m_Sua, m_Xoa As Boolean
    Private m_flagShowGroupPanel_ChiTiet01, m_flagShowGroupPanel_ChiTiet02, m_flagShowGroupPanel_ChiTiet03, m_flagShowGroupPanel_ChiTiet04, m_flagShowGroupPanel_ChiTiet05, m_flagShowGroupPanel_ChiTiet06
    Private m_flagShowGroupPanel_Ds01, m_flagShowGroupPanel_Ds02, m_flagShowGroupPanel_Ds03, m_flagShowGroupPanel_Ds04, m_flagShowGroupPanel_Ds05, m_flagShowGroupPanel_Ds06, m_flagShowGroupPanel_Ds07
    Private m_flagShowGroupPanel_ThamChieu01, m_flagShowGroupPanel_ThamChieu03, m_flagShowGroupPanel_ThamChieu04, m_flagShowGroupPanel_ThamChieu05
    Private m_TenDoiTuongXoa As String = ""
    Private selection_Renamed As GridCheckMarksSelection
    Private iclass As IClass = New IClass
    Private ds As DataSet
    Private dt, dt1, dt2, dt3, dt4, dt5, dt6, dt7, dt8, dt9, dt10, dtPopUp1, dtPopUp2 As DataTable
    Private bd, bd1, bd2, bd3, bd4, bd5, bd6, bd7, bd8, bd9, bd10, bdPopUp1, bdPopUp2 As BindingSource
    Private am, ad As Object
    Private state As Integer
    Private controlFirst, controlLast As BaseEdit
    Private SoTab As Integer 'số tab sử dụng
    Private SoTabThamChieu As Integer = 0
    Private flag1, flag2, flag3, flag4, flag5, flag6 As Boolean  'tránh loop xtragrid
    Protected flagInitNewRow1 As Boolean = True
    Protected flagInitNewRow2 As Boolean = True
    Protected flagInitNewRow3 As Boolean = True
    Protected flagInitNewRow4 As Boolean = True
    Protected flagInitNewRow5 As Boolean = True
    Protected flagInitNewRow6 As Boolean = True
    Private colex, colthiet As GridColumn
    Private ht1, ht2, ht3, ht4, ht5, ht6 As Hashtable 'cột thay đổi
    Private htControlValue As Hashtable 'giá trị control trên thông tin form 
    Private lst1, lst2, lst3, lst4, lst5, lst6, lstGuidDeleted, lstGuIdDeleted_tab1, lstGuIdDeleted_tab2, lstGuIdDeleted_tab3, lstGuIdDeleted_tab4, lstGuIdDeleted_tab5, lstGuIdDeleted_tab6 As ArrayList 'danh sách cột thay đổi
    Dim htNew, htEdit, htEditTab1, htEditTab2, htEditTab3, htEditTab4, htEditTab5, htEditTab6 As Hashtable
    Public Sub setShowGroupBox_ChiTiet01()
        Me.m_flagShowGroupPanel_ChiTiet01 = True
    End Sub
    Public Sub setShowGroupBox_ChiTiet02()
        Me.m_flagShowGroupPanel_ChiTiet02 = True
    End Sub
    Public Sub setShowGroupBox_ChiTiet03()
        Me.m_flagShowGroupPanel_ChiTiet03 = True
    End Sub
    '...
    ''' <summary>
    ''' set tên đối tượng xóa hiển thị trên messagebox khi xóa
    ''' </summary>
    ''' <param name="ten_doi_tuong_xoa">tên đối tượng xóa cần hiển thị lên messagebox khi xóa</param>
    ''' <remarks></remarks>
    Public Sub set_Messagebox_TenDoiTuongXoa(ByVal ten_doi_tuong_xoa As String)
        Me.m_TenDoiTuongXoa = ten_doi_tuong_xoa
    End Sub
    ''' <summary>
    ''' Đánh dấu đã tạo dòng rồi (cho igridviewchitiet01)
    ''' </summary>
    ''' <param name="b">true</param>
    ''' <remarks></remarks>
    Protected Sub setFlagInitNewRowTab1(ByVal b As Boolean)
        Me.flagInitNewRow1 = b
    End Sub
    ''' <summary>
    ''' Đánh dấu đã tạo dòng rồi (cho igridviewchitiet02)
    ''' </summary>
    ''' <param name="b">true</param>
    ''' <remarks></remarks>
    Protected Sub setFlagInitNewRowTab2(ByVal b As Boolean)
        Me.flagInitNewRow2 = b
    End Sub
    ''' <summary>
    ''' Đánh dấu đã tạo dòng rồi (cho igridviewchitiet03)
    ''' </summary>
    ''' <param name="b">true</param>
    ''' <remarks></remarks>
    Protected Sub setFlagInitNewRowTab3(ByVal b As Boolean)
        Me.flagInitNewRow3 = b
    End Sub
    ''' <summary>
    ''' Đánh dấu đã tạo dòng rồi (cho igridviewchitiet04)
    ''' </summary>
    ''' <param name="b">true</param>
    ''' <remarks></remarks>
    Protected Sub setFlagInitNewRowTab4(ByVal b As Boolean)
        Me.flagInitNewRow4 = b
    End Sub
    ''' <summary>
    ''' Đánh dấu đã tạo dòng rồi (cho igridviewchitiet05)
    ''' </summary>
    ''' <param name="b">true</param>
    ''' <remarks></remarks>
    Protected Sub setFlagInitNewRowTab5(ByVal b As Boolean)
        Me.flagInitNewRow5 = b
    End Sub
    ''' <summary>
    ''' Đánh dấu đã tạo dòng rồi (cho igridviewchitiet06)
    ''' </summary>
    ''' <param name="b">true</param>
    ''' <remarks></remarks>
    Protected Sub setFlagInitNewRowTab6(ByVal b As Boolean)
        Me.flagInitNewRow6 = b
    End Sub
    Private Sub View_SelectionChanged(sender As Object, e As DevExpress.Data.SelectionChangedEventArgs)
        Dim gridView As GridView = DirectCast(sender, GridView)
        Select Case e.Action
            Case CollectionChangeAction.Add
                gridView.SetRowCellValue(e.ControllerRow, gridView.Columns("Mark"), True)
                Exit Select
            Case CollectionChangeAction.Remove
                gridView.SetRowCellValue(e.ControllerRow, gridView.Columns("Mark"), False)
                Exit Select
            Case CollectionChangeAction.Refresh
                For i As Integer = 0 To gridView.DataRowCount - 1
                    gridView.SetRowCellValue(i, gridView.Columns("Mark"), gridView.IsRowSelected(gridView.GetVisibleRowHandle(i)))
                Next
                Exit Select
        End Select
    End Sub
    Private Sub View_MouseDown(sender As Object, e As MouseEventArgs)
        Try
            Dim gridView As GridView = DirectCast(sender, GridView)
            Dim hInfo As GridHitInfo = gridView.CalcHitInfo(e.Location)
            If hInfo.InRowCell Then
                If gridView.IsRowSelected(hInfo.RowHandle) Then
                    gridView.UnselectRow(hInfo.RowHandle)
                Else
                    gridView.SelectRow(hInfo.RowHandle)
                End If
                DirectCast(e, DXMouseEventArgs).Handled = True
            End If
        Catch ex As Exception
            MessageBox.Show("view_mousedown" & ex.Message)
        End Try
        'If gridView.CalcHitInfo(e.Location).InRow Then
        '    DirectCast(e, DXMouseEventArgs).Handled = True
        'End If
    End Sub
    Private Sub view_CustomDrawRowIndicator(sender As Object, e As DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs) Handles view.CustomDrawRowIndicator
        Dim view As GridView = DirectCast(sender, GridView)
        Dim indicatorIcon As Boolean = False
        If e.RowHandle >= 0 Then 'trừ trường hợp -1
            'Check whether the indicator cell belongs to a data row
            If e.Info.IsRowIndicator Then
                e.Info.DisplayText = (e.RowHandle + 1).ToString()
                If Not indicatorIcon Then
                    e.Info.ImageIndex = -1
                End If
            End If
        End If
    End Sub
    Private WithEvents view As DevExpress.XtraGrid.Views.Grid.GridView
    ''' <summary>
    ''' set giá trị trong phần thông tin trước khi lưu
    ''' khai báo trong new() của form
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuu(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEdit.ContainsKey(tên_cột) Then
            htEdit.Remove(tên_cột)
            htEdit.Add(tên_cột, giá_trị)
        Else
            Me.htEdit.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' set giá trị phần tab1 trước khi lưu
    ''' khai báo trong Public Overrides Sub setSubTruoc_Luu()() của form
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuuTab1(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEditTab1.ContainsKey(tên_cột) Then
            htEditTab1.Remove(tên_cột)
            htEditTab1.Add(tên_cột, giá_trị)
        Else
            Me.htEditTab1.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' set giá trị phần tab2 trước khi lưu
    ''' khai báo trong Public Overrides Sub setSubTruoc_Luu()() của form
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuuTab2(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEditTab2.ContainsKey(tên_cột) Then
            htEditTab2.Remove(tên_cột)
            htEditTab2.Add(tên_cột, giá_trị)
        Else
            Me.htEditTab2.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' set giá trị phần tab3 trước khi lưu
    ''' khai báo trong Public Overrides Sub setSubTruoc_Luu()() của form
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuuTab3(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEditTab3.ContainsKey(tên_cột) Then
            htEditTab3.Remove(tên_cột)
            htEditTab3.Add(tên_cột, giá_trị)
        Else
            Me.htEditTab3.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' set giá trị phần tab4 trước khi lưu
    ''' khai báo trong Public Overrides Sub setSubTruoc_Luu()() của form
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuuTab4(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEditTab4.ContainsKey(tên_cột) Then
            htEditTab4.Remove(tên_cột)
            htEditTab4.Add(tên_cột, giá_trị)
        Else
            Me.htEditTab4.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' set giá trị phần tab5 trước khi lưu
    ''' (khai báo trong Public Overrides Sub setSubTruoc_Luu()() của form)
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuuTab5(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEditTab5.ContainsKey(tên_cột) Then
            htEditTab5.Remove(tên_cột)
            htEditTab5.Add(tên_cột, giá_trị)
        Else
            Me.htEditTab5.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' set giá trị phần tab6 trước khi lưu
    ''' khai báo trong Public Overrides Sub setSubTruoc_Luu()() của form
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setSuaTruocKhiLuuTab6(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htEditTab6.ContainsKey(tên_cột) Then
            htEditTab6.Remove(tên_cột)
            htEditTab6.Add(tên_cột, giá_trị)
        Else
            Me.htEditTab6.Add(tên_cột, giá_trị)
        End If
    End Sub
    ''' <summary>
    ''' Set thông tin của doanh nghiệp 
    ''' </summary>
    ''' <param name="company">Tên công ty</param>
    ''' <param name="address">Địa chỉ</param>
    ''' <remarks></remarks>
    Public Sub setHeaderFooter(ByVal company As String, ByVal address As String)
        Me.IGridViewChiTiet01.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLink1)
        Me.IGridViewChiTiet02.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLink2)
        Me.IGridViewChiTiet03.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLink3)
        Me.IGridViewChiTiet04.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLink4)
        Me.IGridViewChiTiet05.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLink5)
        Me.IGridViewChiTiet06.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLink6)
        Me.IGridViewDs01.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs01)
        Me.IGridViewDs02.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs02)
        Me.IGridViewDs03.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs03)
        Me.IGridViewDs04.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs04)
        Me.IGridViewDs05.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs05)
        Me.IGridViewDs06.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs06)
        Me.IGridViewDs07.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkDs07)
        Me.IGridViewPopUp1.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkPop1)
        Me.IGridViewPopUp2.setHeaderFooter(company, address, "", Me.printingSystem1, Me.PrintableComponentLinkPop2)
    End Sub
    ''' <summary>
    ''' set giá trị mặc định cho các cột ẩn khi tạo mới
    ''' khai báo trong Public Overrides sub setSubSau_TaoMoi()
    ''' </summary>
    ''' <param name="tên_cột">Tên cột</param>
    ''' <param name="giá_trị">Giá trị</param>
    ''' <remarks></remarks>
    Public Sub setMacDinhCotAn(ByVal tên_cột As String, ByVal giá_trị As Object)
        If htNew.ContainsKey(tên_cột) Then
            htNew.Remove(tên_cột)
            htNew.Add(tên_cột, giá_trị)
        Else
            Me.htNew.Add(tên_cột, giá_trị)
        End If
    End Sub
    Public Overridable Sub setSubTruoc_UpdateAll()
    End Sub
    Public Overridable Sub setSubTruoc_Luu()
    End Sub
    Public Overridable Sub setSubSau_Luu()
    End Sub
    Public Overridable Sub setSubTruoc_TaoMoi()
    End Sub
    Public Overridable Sub setSubSau_TaoMoi()
    End Sub
    Public Overridable Sub setSubTruoc_Sua()
    End Sub
    Public Overridable Sub setSubSau_Sua()
    End Sub
    Public Overridable Sub setSubTruoc_Xoa()
    End Sub
    Public Overridable Sub setSubSau_Xoa()
    End Sub
    Public Overridable Sub setSubTruoc_HuyThayDoi()
    End Sub
    Public Overridable Sub setSubSau_HuyThayDoi()
    End Sub
    Public Overridable Sub setSubTruoc_In()
    End Sub
    Public Overridable Sub setSubSau_In()
    End Sub
    Public Overridable Sub setSubTruoc_Thoat()
    End Sub
    Public Overridable Sub setSubTruoc_LamTuoi()
    End Sub
    Public Overridable Sub setSubSau_LamTuoi()
    End Sub
    Public Overridable Sub setSubTruoc_DauTien()
    End Sub
    Public Overridable Sub setSubSau_DauTien()
    End Sub
    Public Overridable Sub setSubTruoc_Truoc()
    End Sub
    Public Overridable Sub setSubSau_Truoc()
    End Sub
    Public Overridable Sub setSubTruoc_Sau()
    End Sub
    Public Overridable Sub setSubSau_Sau()
    End Sub
    Public Overridable Sub setSubTruoc_Cuoi()
    End Sub
    Public Overridable Sub setSubSau_Cuoi()
    End Sub
    '=====================================================
    Public Overridable Function setFuncTruoc_Luu() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_Luu() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_TaoMoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_TaoMoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_Sua() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_Sua() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_HuyThayDoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_Xoa() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_Xoa() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_HuyThayDoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_In() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_in() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_Thoat() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_LamTuoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_LamTuoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_DauTien() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_DauTien() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_Truoc() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_Truoc() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_Sau() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_Sau() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncTruoc_Cuoi() As Boolean
        Return True
    End Function
    Public Overridable Function setFuncSau_Cuoi() As Boolean
        Return True
    End Function
    '=========== set tab đối tượng ===========
    'truong hop form doi
    ''' <summary>
    ''' set các đối tượng cho tab1
    ''' </summary>
    ''' <param name="dt1">datatable tương ứng của tab1</param>
    ''' <param name="bd1">bindingsource tương ứng của tab1 (nhớ là FK...)</param>
    ''' <param name="ad1">tableadapter tương ứng của tab1</param>
    ''' <remarks></remarks>
    Public Sub setTab1(ByVal dt1 As DataTable, ByVal bd1 As BindingSource, ByVal ad1 As Object)
        Me.dt1 = dt1
        Me.bd1 = bd1
        Me.iclass.addTab1(dt1, bd1, ad1, Me.IGridViewChiTiet01)
    End Sub
    ''' <summary>
    ''' set các đối tượng cho tab2
    ''' </summary>
    ''' <param name="dt2">datatable tương ứng của tab2</param>
    ''' <param name="bd2">bindingsource tương ứng của tab2 (nhớ là FK...)</param>
    ''' <param name="ad2">tableadapter tương ứng của tab2</param>
    ''' <remarks></remarks>
    Public Sub setTab2(ByVal dt2 As DataTable, ByVal bd2 As BindingSource, ByVal ad2 As Object)
        Me.dt2 = dt2
        Me.bd2 = bd2
        Me.iclass.addTab1(dt2, bd2, ad2, IGridViewChiTiet02)
    End Sub
    ''' <summary>
    ''' set các đối tượng cho tab3
    ''' </summary>
    ''' <param name="dt3">datatable tương ứng của tab3</param>
    ''' <param name="bd3">bindingsource tương ứng của tab3 (nhớ là FK...)</param>
    ''' <param name="ad3">tableadapter tương ứng của tab3</param>
    ''' <remarks></remarks>
    Public Sub setTab3(ByVal dt3 As DataTable, ByVal bd3 As BindingSource, ByVal ad3 As Object)
        Me.dt3 = dt3
        Me.bd3 = bd3
        Me.iclass.addTab1(dt3, bd3, ad3, IGridViewChiTiet03)
    End Sub
    ''' <summary>
    ''' set các đối tượng cho tab4
    ''' </summary>
    ''' <param name="dt4">datatable tương ứng của tab4</param>
    ''' <param name="bd4">bindingsource tương ứng của tab4 (nhớ là FK...)</param>
    ''' <param name="ad4">tableadapter tương ứng của tab4</param>
    ''' <remarks></remarks>
    Public Sub setTab4(ByVal dt4 As DataTable, ByVal bd4 As BindingSource, ByVal ad4 As Object)
        Me.dt4 = dt4
        Me.bd4 = bd4
        Me.iclass.addTab1(dt4, bd4, ad4, IGridViewChiTiet04)
    End Sub
    ''' <summary>
    ''' set các đối tượng cho tab5
    ''' </summary>
    ''' <param name="dt5">datatable tương ứng của tab5</param>
    ''' <param name="bd5">bindingsource tương ứng của tab5 (nhớ là FK...)</param>
    ''' <param name="ad5">tableadapter tương ứng của tab5</param>
    ''' <remarks></remarks>
    Public Sub setTab5(ByVal dt5 As DataTable, ByVal bd5 As BindingSource, ByVal ad5 As Object)
        Me.dt5 = dt5
        Me.bd5 = bd5
        Me.iclass.addTab1(dt5, bd5, ad5, IGridViewChiTiet05)
    End Sub
    ''' <summary>
    ''' set các đối tượng cho tab6
    ''' </summary>
    ''' <param name="dt6">datatable tương ứng của tab6</param>
    ''' <param name="bd6">bindingsource tương ứng của tab6 (nhớ là FK...)</param>
    ''' <param name="ad6">tableadapter tương ứng của tab6</param>
    ''' <remarks></remarks>
    Public Sub setTab6(ByVal dt6 As DataTable, ByVal bd6 As BindingSource, ByVal ad6 As Object)
        Me.dt6 = dt6
        Me.bd6 = bd6
        Me.iclass.addTab1(dt6, bd6, ad6, IGridViewChiTiet06)
    End Sub
    '=========== end set tab đối tượng =======
    '=========== set popup đối tượng ===========
    ''' <summary>
    ''' Set đối tượng của phần popup 1
    ''' </summary>
    ''' <param name="dtpopup1">datatable của popup1</param>
    ''' <param name="bdpopup1">bindingsource của phần popup1</param>
    ''' <param name="adpopup1">adapter của popup1</param>
    ''' <remarks></remarks>
    Public Sub setPopUp1(ByVal dtpopup1 As DataTable, ByVal bdpopup1 As BindingSource, ByVal adpopup1 As Object)
        Me.dtPopUp1 = dtpopup1
        Me.bdPopUp1 = bdpopup1
        'Me.iclass.addTab1(dt6, bd6, ad6, IGridViewChiTiet06)
    End Sub
    ''' <summary>
    ''' set đối tượng của phần popup2
    ''' </summary>
    ''' <param name="dtpopup2">datatable của popup2</param>
    ''' <param name="bdpopup2">bindingsource của popup2</param>
    ''' <param name="adpopup2">adapter của popup2</param>
    ''' <remarks></remarks>
    Public Sub setPopUp2(ByVal dtpopup2 As DataTable, ByVal bdpopup2 As BindingSource, ByVal adpopup2 As Object)
        Me.dtPopUp2 = dtpopup2
        Me.bdPopUp2 = bdpopup2
        'Me.iclass.addTab1(dt6, bd6, ad6, IGridViewChiTiet06)
    End Sub
    '=========== end set popup đối tượng =======
    ''' <summary>
    ''' set các đối tượng của form đơn
    ''' </summary>
    ''' <param name="ds">Tên DataSet</param>
    ''' <param name="dt">Tên Datatable</param>
    ''' <param name="bd">Tên BidingSource</param>
    ''' <param name="am">Tên TableAdapterManager</param>
    '''  <param name="ad">Tên TableAdapter</param>
    ''' <param name="controlFirst">Tên control đầu tiên để bắt focus</param>
    '''  <param name="controlLast">Tên control cuối cùng để nhảy xuống lưới</param>
    ''' <remarks></remarks>
    Public Sub setObj(ByVal ds As DataSet, ByVal dt As DataTable, ByVal bd As BindingSource, ByVal am As Object, ByVal ad As Object, ByVal controlFirst As BaseEdit, ByVal controlLast As BaseEdit)
        Me.bd = bd
        Me.ds = ds
        Me.dt = dt
        Me.am = am
        Me.ad = ad
        Me.controlFirst = controlFirst
        Me.controlLast = controlLast
        AddHandler controlLast.KeyDown, AddressOf controlLast_KeyDown
        iclass.setObj(ds, dt, bd, am, ad, controlFirst)
    End Sub
    Public Function getKiemTraMaTonTai(ByVal sMa As String) As Boolean 'kiểm tra sự tồn tại của mã - dùng kiểm tra chung với igridview
        If Me.bd.Find("ma", sMa) = -1 Then 'nếu -1 nghĩa là ko tìm đc vị trí trong bindingsource
            Return False
        Else 'còn lại là tìm đc vị trí --> đã tồn tại
            Return True
        End If
    End Function
    Private Sub setReadonlyControl(ByVal b As Boolean)
        setReadonly(Me.LayoutControl1, b)
        If b Then
            Try
                Me.IGridViewChiTiet01.OptionsBehavior.Editable = False
                Me.IGridViewChiTiet01.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
                Me.IGridViewChiTiet02.OptionsBehavior.Editable = False
                Me.IGridViewChiTiet02.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
                Me.IGridViewChiTiet03.OptionsBehavior.Editable = False
                Me.IGridViewChiTiet03.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
                Me.IGridViewChiTiet04.OptionsBehavior.Editable = False
                Me.IGridViewChiTiet04.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
                Me.IGridViewChiTiet05.OptionsBehavior.Editable = False
                Me.IGridViewChiTiet05.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
                Me.IGridViewChiTiet06.OptionsBehavior.Editable = False
                Me.IGridViewChiTiet06.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.None
                Me.IGridViewDs01.setLock(False)
            Catch ex As Exception
            End Try
        Else
            Try
                Me.IGridViewChiTiet01.OptionsBehavior.Editable = True
                Me.IGridViewChiTiet01.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
                Me.IGridViewChiTiet02.OptionsBehavior.Editable = True
                Me.IGridViewChiTiet02.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
                Me.IGridViewChiTiet03.OptionsBehavior.Editable = True
                Me.IGridViewChiTiet03.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
                Me.IGridViewChiTiet04.OptionsBehavior.Editable = True
                Me.IGridViewChiTiet04.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
                Me.IGridViewChiTiet05.OptionsBehavior.Editable = True
                Me.IGridViewChiTiet05.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
                Me.IGridViewChiTiet06.OptionsBehavior.Editable = True
                Me.IGridViewChiTiet06.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom
                Me.IGridViewDs01.setLock(True)
            Catch ex As Exception
            End Try
        End If
        If b Then
            Me.DxValidationProvider1.ValidationMode = DevExpress.XtraEditors.DXErrorProvider.ValidationMode.Manual
            setButtonTrangThaiSua(False)
        Else
            Me.DxValidationProvider1.ValidationMode = DevExpress.XtraEditors.DXErrorProvider.ValidationMode.Auto
            setButtonTrangThaiSua(True)
        End If
    End Sub
    Private Sub setButtonTrangThaiSua(ByVal b As Boolean) 'set nút lưu và xóa - khi ở trạng thái sửa thì mới cho phép thao tác trên nó (enable = true) - các trạng thái khác thì không cho (enable = false)
        Me.BarButtonGroupLuu.Enabled = b
        Me.BarButtonItemLuu.Enabled = b
        Me.BarStaticItemLuu.Enabled = b
        '==============================
        If m_Xoa Then
            Me.BarButtonItemXoa.Enabled = True
            Me.BarButtonGroupXoa.Enabled = True
            Me.BarStaticItemXoa.Enabled = True
        End If
        '===============================
        Me.BarButtonItemHuyThayDoi.Enabled = b
        Me.BarButtonGroupHuyThayDoi.Enabled = b
        Me.BarStaticItemHuyThayDoi.Enabled = b
        'Me.BarButtonItemLuu.Enabled = b
        'Me.BarButtonGroupLuu.Enabled = b
        'Me.BarStaticItemLuu.Enabled = b
        If b Then 'xử lý nút sửa (nếu nút lưu - xóa cho phép thì sửa ko cho phép và ngược lại)
            If m_TaoMoi Then
                Me.BarButtonItemTaoMoi.Enabled = False
                Me.BarButtonGroupTaoMoi.Enabled = False
                Me.BarStaticItemTaoMoi.Enabled = False
            End If
            Me.BarButtonItemSua.Enabled = False
            Me.BarButtonGroupSua.Enabled = False
            Me.BarStaticItemSua.Enabled = False
            Me.BarButtonItemFirst.Enabled = False
            Me.BarButtonItemPrevious.Enabled = False
            Me.BarButtonItemNext.Enabled = False
            Me.BarButtonItemLast.Enabled = False
            Me.BarButtonGroupDieuHuong.Enabled = False
            Me.BarButtonItemBaoCao.Enabled = False
            Me.BarButtonGroupBaoCao.Enabled = False
            Me.BarStaticItemBaoCao.Enabled = False
        Else
            If m_TaoMoi Then
                Me.BarButtonItemTaoMoi.Enabled = True
                Me.BarButtonGroupTaoMoi.Enabled = True
                Me.BarStaticItemTaoMoi.Enabled = True
            End If
            Me.BarButtonItemSua.Enabled = True
            Me.BarButtonGroupSua.Enabled = True
            Me.BarStaticItemSua.Enabled = True
            Me.BarButtonItemFirst.Enabled = True
            Me.BarButtonItemPrevious.Enabled = True
            Me.BarButtonItemNext.Enabled = True
            Me.BarButtonItemLast.Enabled = True
            Me.BarButtonGroupDieuHuong.Enabled = True
            Me.BarButtonItemBaoCao.Enabled = True
            Me.BarButtonGroupBaoCao.Enabled = True
            Me.BarStaticItemBaoCao.Enabled = True
        End If
        setTrangThaiSuaChiTiet(b)
        Me.RibbonControl.Refresh()
    End Sub
    Private Sub setTrangThaiSuaChiTiet(ByVal b As Boolean)
        Me.BarButtonItemTaoMoiChiTiet.Enabled = b
        Me.BarButtonGroupTaoMoiChiTiet.Enabled = b
        Me.BarStaticItemTaoMoiChiTiet.Enabled = b
        Me.BarButtonItemHuyThayDoiChiTiet.Enabled = b
        Me.BarButtonGroupHuyThayDoiChiTiet.Enabled = b
        Me.BarStaticItemHuyThayDoiChiTiet.Enabled = b
        Me.BarButtonItemXoaChiTiet.Enabled = b
        Me.BarButtonGroupXoaChiTiet.Enabled = b
        Me.BarStaticItemXoaChiTiet.Enabled = b
        Me.RibbonControl1.Refresh()
    End Sub
    Protected Overridable Sub BarButtonItemTaoMoi_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoi.ItemClick, BarButtonGroupTaoMoi.ItemClick, BarStaticItemTaoMoi.ItemClick
        Me.setSubTruoc_TaoMoi()
        If Me.setFuncTruoc_TaoMoi() Then
            Me.setReadonlyControl(False)
            Dim row As DataRowView = CType(Me.bd.AddNew(), DataRowView)
            Me.controlFirst.Focus()
            If TypeOf controlFirst Is ISearchLookupEdit Then
                DirectCast(controlFirst, ISearchLookupEdit).ShowPopup()
            End If
            Me.state = 1
            'set sub sau tạo mới
            Me.setSubSau_TaoMoi()
            'xử lý set giá trị mặc định trên thông tin
            Dim Item As DictionaryEntry
            For Each Item In htNew
                If Me.dt.Columns.Contains(Item.Key.ToString) Then
                    row(Item.Key.ToString) = Item.Value
                Else
                    DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setMacDinhCotAn' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            Next

        End If
    End Sub
    Private Sub setLstGuiDeleted()
        If dt IsNot Nothing Then
            Dim myView As New DataView(dt, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable As DataTable = myView.ToTable()
            lstGuidDeleted.Clear()
            For Each deletedRow As DataRow In myTable.Rows
                lstGuidDeleted.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab1 ======================================
        If dt1 IsNot Nothing Then
            Dim myView1 As New DataView(dt1, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab1 As DataTable = myView1.ToTable()
            lstGuIdDeleted_tab1.Clear()
            For Each deletedRow As DataRow In myTable_tab1.Rows
                lstGuIdDeleted_tab1.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab2 ======================================
        If dt2 IsNot Nothing Then
            Dim myView2 As New DataView(dt2, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab2 As DataTable = myView2.ToTable()
            lstGuIdDeleted_tab2.Clear()
            For Each deletedRow As DataRow In myTable_tab2.Rows
                lstGuIdDeleted_tab2.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab3 ======================================
        If dt3 IsNot Nothing Then
            Dim myView3 As New DataView(dt3, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab3 As DataTable = myView3.ToTable()
            lstGuIdDeleted_tab3.Clear()
            For Each deletedRow As DataRow In myTable_tab3.Rows
                lstGuIdDeleted_tab3.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab4 ======================================
        If dt4 IsNot Nothing Then
            Dim myView4 As New DataView(dt4, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab4 As DataTable = myView4.ToTable()
            lstGuIdDeleted_tab4.Clear()
            For Each deletedRow As DataRow In myTable_tab4.Rows
                lstGuIdDeleted_tab4.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab5 ======================================
        If dt5 IsNot Nothing Then
            Dim myView5 As New DataView(dt5, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab5 As DataTable = myView5.ToTable()
            lstGuIdDeleted_tab5.Clear()
            For Each deletedRow As DataRow In myTable_tab5.Rows
                lstGuIdDeleted_tab5.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
        '============== tab6 ======================================
        If dt6 IsNot Nothing Then
            Dim myView6 As New DataView(dt6, Nothing, Nothing, DataViewRowState.Deleted)
            Dim myTable_tab6 As DataTable = myView6.ToTable()
            lstGuIdDeleted_tab6.Clear()
            For Each deletedRow As DataRow In myTable_tab6.Rows
                lstGuIdDeleted_tab6.Add(CType(deletedRow.Item("uid"), System.Guid))
            Next
        End If
    End Sub
    Private Sub iGridSetUpdateData()
        Me.IGridViewChiTiet01.setUpdateData()
        Me.IGridViewChiTiet02.setUpdateData()
        Me.IGridViewChiTiet03.setUpdateData()
        Me.IGridViewChiTiet04.setUpdateData()
        Me.IGridViewChiTiet05.setUpdateData()
        Me.IGridViewChiTiet06.setUpdateData()
    End Sub
    Private Sub BdEndEdit()
        If bd1 IsNot Nothing Then
            bd1.EndEdit()
        End If
        If bd2 IsNot Nothing Then
            bd2.EndEdit()
        End If
        If bd3 IsNot Nothing Then
            bd3.EndEdit()
        End If
        If bd4 IsNot Nothing Then
            bd4.EndEdit()
        End If
        If bd5 IsNot Nothing Then
            bd5.EndEdit()
        End If
        If bd6 IsNot Nothing Then
            bd6.EndEdit()
        End If
    End Sub
    Private Function getSave()
        Try
            'Me.igridview.setUpdateData()
            bd.EndEdit()
            iGridSetUpdateData() 'update lưới
            BdEndEdit() 'end edit các tab
            If Me.ds.HasChanges Then 'coi có thay đổi dữ liệu hay ko ?
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Lưu' không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    setLstGuiDeleted()
                    setSubTruoc_UpdateAll()
                    am.updateAll(Me.ds)
                Else
                    ds.RejectChanges()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    'Private Sub getLst1() 'lấy danh sách cột thay đổi - coder khỏi nhập vô danh sách này - dò trong fk
    '    Dim stencot, dataType As String
    '    If dt1 IsNot Nothing Then
    '        For Each col As DataColumn In dt1.Columns
    '            stencot = col.ColumnName
    '            dataType = dt.Columns(stencot).DataType.ToString
    '            'set default
    '            If (dataType = "System.Double" Or dataType = "System.Decimal" Or dataType = "System.Int16" Or dataType = "System.Int32" Or dataType = "System.Int64") Then 'kiểu 
    '                lst1.Add(stencot)
    '            End If
    '        Next
    '    End If
    'End Sub

    Protected Overridable Sub BarButtonItemLuu_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLuu.ItemClick, BarStaticItemLuu.ItemClick
        Me.setSubTruoc_Luu()
        If Me.setFuncTruoc_Luu() Then
            Me.bd.EndEdit() 'sửa trước khi lưu (trước tạo mới)
            'sửa trước khi lưu (cha)
            Dim row As DataRowView = CType(Me.bd.Current(), DataRowView)
            Dim Item As DictionaryEntry
            For Each Item In htEdit
                If dt.Columns.Contains(Item.Key.ToString) Then
                    row(Item.Key.ToString) = Item.Value
                Else
                    DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setMacDinhCotAn' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            Next
            'sửa trước khi lưu (con - tab1)
            Dim Item1 As DictionaryEntry
            For Each Item1 In htEditTab1
                For index = 0 To Me.IGridViewChiTiet01.RowCount - 1
                    If Me.IGridViewChiTiet01.Columns.Contains(Me.IGridViewChiTiet01.Columns.ColumnByFieldName(Item1.Key.ToString)) Then
                        Me.IGridViewChiTiet01.SetRowCellValue(index, Me.IGridViewChiTiet01.Columns.ColumnByFieldName(Item1.Key.ToString), Item1.Value)
                    Else
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item1.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setSuaTruocKhiLuuTab1' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Next
            Next
            'sửa trước khi lưu (con - tab2)
            Dim Item2 As DictionaryEntry
            For Each Item2 In htEditTab2
                For index = 0 To Me.IGridViewChiTiet02.RowCount - 1
                    If Me.IGridViewChiTiet02.Columns.Contains(Me.IGridViewChiTiet02.Columns.ColumnByFieldName(Item2.Key.ToString)) Then
                        Me.IGridViewChiTiet02.SetRowCellValue(index, Me.IGridViewChiTiet02.Columns.ColumnByFieldName(Item2.Key.ToString), Item2.Value)
                    Else
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item2.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setSuaTruocKhiLuuTab2' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Next
            Next
            'sửa trước khi lưu (con - tab3)
            Dim Item3 As DictionaryEntry
            For Each Item3 In htEditTab3
                For index = 0 To Me.IGridViewChiTiet03.RowCount - 1
                    If Me.IGridViewChiTiet03.Columns.Contains(Me.IGridViewChiTiet03.Columns.ColumnByFieldName(Item3.Key.ToString)) Then
                        Me.IGridViewChiTiet03.SetRowCellValue(index, Me.IGridViewChiTiet03.Columns.ColumnByFieldName(Item3.Key.ToString), Item3.Value)
                    Else
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item3.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setSuaTruocKhiLuuTab3' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Next
            Next
            'sửa trước khi lưu (con - tab4)
            Dim Item4 As DictionaryEntry
            For Each Item4 In htEditTab4
                For index = 0 To Me.IGridViewChiTiet04.RowCount - 1
                    If Me.IGridViewChiTiet04.Columns.Contains(Me.IGridViewChiTiet04.Columns.ColumnByFieldName(Item4.Key.ToString)) Then
                        Me.IGridViewChiTiet04.SetRowCellValue(index, Me.IGridViewChiTiet04.Columns.ColumnByFieldName(Item4.Key.ToString), Item4.Value)
                    Else
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item4.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setSuaTruocKhiLuuTab4' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Next
            Next
            'sửa trước khi lưu (con - tab5)
            Dim Item5 As DictionaryEntry
            For Each Item5 In htEditTab5
                For index = 0 To Me.IGridViewChiTiet05.RowCount - 1
                    If Me.IGridViewChiTiet05.Columns.Contains(Me.IGridViewChiTiet05.Columns.ColumnByFieldName(Item5.Key.ToString)) Then
                        Me.IGridViewChiTiet05.SetRowCellValue(index, Me.IGridViewChiTiet05.Columns.ColumnByFieldName(Item5.Key.ToString), Item5.Value)
                    Else
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item5.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setSuaTruocKhiLuuTab5' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Next
            Next
            'sửa trước khi lưu (con - tab6)
            Dim Item6 As DictionaryEntry
            For Each Item6 In htEditTab6
                For index = 0 To Me.IGridViewChiTiet06.RowCount - 1
                    If Me.IGridViewChiTiet06.Columns.Contains(Me.IGridViewChiTiet06.Columns.ColumnByFieldName(Item6.Key.ToString)) Then
                        Me.IGridViewChiTiet06.SetRowCellValue(index, Me.IGridViewChiTiet06.Columns.ColumnByFieldName(Item6.Key.ToString), Item6.Value)
                    Else
                        DevExpress.XtraEditors.XtraMessageBox.Show("Cột '" & Item6.Key.ToString & "' không tồn tại, bạn coi lại hàm 'setSuaTruocKhiLuuTab6' ?", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Next
            Next
            IGridViewChiTiet01.setUpdateData()
            IGridViewChiTiet02.setUpdateData()
            IGridViewChiTiet03.setUpdateData()
            IGridViewChiTiet04.setUpdateData()
            IGridViewChiTiet05.setUpdateData()
            IGridViewChiTiet06.setUpdateData()
            If Not IsNothing(bd1) Then
                Try
                    Me.bd1.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try

            End If
            If Not IsNothing(bd2) Then
                Try
                    Me.bd2.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd3) Then
                Try
                    Me.bd3.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd4) Then
                Try
                    Me.bd4.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd5) Then
                Try
                    Me.bd5.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd6) Then
                Try
                    Me.bd6.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            '=======================================
            'If iclass.getSave() And state <> 0 Then
            If state <> 0 Then
                If Me.getSave Then
                    setReadonlyControl(True)
                    Me.state = 0
                    Me.setSubSau_Luu()
                End If
            End If
        End If
    End Sub
    'kiểm tra trường hợp chưa có dữ liệu
    Private Function checkBindingSource() As Boolean
        If IsNothing(bd) Then
            DevExpress.XtraEditors.XtraMessageBox.Show("chưa set đối tượng cho form đó ku (>:D) : Me.setobj(<...>) !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop)

        Else
            If Me.bd.Count = 0 Then
                Return False
            Else
                Return True
            End If
        End If
    End Function
    Protected Overridable Sub BarButtonItemSua_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemSua.ItemClick, BarStaticItemSua.ItemClick
        Me.setSubTruoc_Sua()
        If checkBindingSource() Then
            If Me.setFuncTruoc_Sua() Then
                setReadonlyControl(False)
                state = 2
                Me.setSubSau_Sua()
            End If
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có dữ liệu để 'Sửa'", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub
    Private Function getDelete()
        Try
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa " & Me.m_TenDoiTuongXoa & " không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Error) = Windows.Forms.DialogResult.Yes Then
                Me.bd.EndEdit()
                Me.bd.RemoveCurrent()
                am.updateAll(Me.ds)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            Return False
        End Try
        Return True
    End Function
    Protected Overridable Sub BarButtonItemXoa_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemXoa.ItemClick, BarStaticItemXoa.ItemClick
        Me.setSubTruoc_Xoa()
        If Me.setFuncTruoc_Xoa Then
            If Me.getDelete() Then
                setReadonlyControl(True)
                Me.state = 0
                Me.setSubSau_Xoa()
            End If
        End If
    End Sub
    Protected Overridable Sub BarButtonItemLamTuoi_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLamTuoi.ItemClick, BarStaticItemLamTuoi.ItemClick
        Me.setSubTruoc_LamTuoi()
        If Me.setFuncTruoc_LamTuoi Then
            If Me.iclass.getRefresh() Then
                setReadonlyControl(True)
                Me.state = 0
                Me.setSubSau_LamTuoi()
            End If
        End If
    End Sub
    Private Sub BarButtonItemBaoCao_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemBaoCao.ItemClick
        Me.setSubTruoc_In()
        If Me.getState <> 0 Then 'lưu trước khi in đảm bảo ko mất dữ liệu !
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Lưu' trước khi in không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                Me.BarButtonItemLuu.PerformClick()
            Else
                Me.BarButtonItemHuyThayDoi.PerformClick()
            End If
        End If
        If Me.setFuncTruoc_In Then
            Me.setSubSau_In()
        End If
    End Sub
    Protected Overridable Sub BarButtonItemHuyThayDoi_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemHuyThayDoi.ItemClick, BarStaticItemHuyThayDoi.ItemClick
        Me.setSubTruoc_HuyThayDoi()
        If setPostEditor(Me.LayoutControl1) Then
            If Me.setFuncTruoc_HuyThayDoi Then
                IGridViewChiTiet01.setUpdateData()
                IGridViewChiTiet02.setUpdateData()
                IGridViewChiTiet03.setUpdateData()
                IGridViewChiTiet04.setUpdateData()
                IGridViewChiTiet05.setUpdateData()
                IGridViewChiTiet06.setUpdateData()
                If Not IsNothing(bd1) Then
                    Try
                        Me.bd1.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd2) Then
                    Try
                        Me.bd2.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd3) Then
                    Try
                        Me.bd3.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd4) Then
                    Try
                        Me.bd4.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd5) Then
                    Try
                        Me.bd5.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd6) Then
                    Try
                        Me.bd6.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Me.iclass.getUndo() Then
                    setReadonlyControl(True)
                    Me.state = 0
                    Me.setSubSau_HuyThayDoi()
                End If
            End If
        End If
    End Sub
    Protected Overridable Sub BarButtonItemFirst_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirst.ItemClick
        Me.setSubTruoc_DauTien()
        If Me.setFuncTruoc_DauTien Then
            Me.iclass.getMoveFirst()
            Me.setSubSau_DauTien()
        End If
    End Sub
    Protected Overridable Sub BarButtonItemPrevious_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPrevious.ItemClick
        Me.setSubTruoc_Truoc()
        If Me.setFuncTruoc_Truoc Then
            Me.iclass.getMovePrevious()
            Me.setSubSau_Truoc()
        End If
    End Sub
    Protected Overridable Sub BarButtonItemNext_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNext.ItemClick
        Me.setSubTruoc_Sau()
        If Me.setFuncTruoc_Sau Then
            Me.iclass.getMoveNext()
            Me.setSubSau_Sau()
        End If
    End Sub
    Protected Overridable Sub BarButtonItemLast_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLast.ItemClick
        Me.setSubTruoc_Cuoi()
        If Me.setFuncTruoc_Cuoi Then
            Me.iclass.getMoveLast()
            Me.setSubSau_Cuoi()
        End If
    End Sub
    Protected Overridable Sub BarButtonItemThoat_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoat.ItemClick, BarStaticItemThoat.ItemClick
        Me.setSubTruoc_Thoat()
        If Me.setFuncTruoc_Thoat Then
            IGridViewChiTiet01.setUpdateData()
            IGridViewChiTiet02.setUpdateData()
            IGridViewChiTiet03.setUpdateData()
            IGridViewChiTiet04.setUpdateData()
            IGridViewChiTiet05.setUpdateData()
            IGridViewChiTiet06.setUpdateData()
            If Not IsNothing(bd1) Then
                Try
                    Me.bd1.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd2) Then
                Try
                    Me.bd2.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd3) Then
                Try
                    Me.bd3.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd4) Then
                Try
                    Me.bd4.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd5) Then
                Try
                    Me.bd5.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If Not IsNothing(bd6) Then
                Try
                    Me.bd6.EndEdit()
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
            If getSave() Then
                Me.Dispose()
                Me.Close()
            End If
        End If
    End Sub

    Protected Overridable Sub IFormDon_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Me.setSubTruoc_Thoat()
        If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn 'Thoát' khỏi màn hình '" & Me.Text & "' không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
            If Me.setFuncTruoc_Thoat Then
                IGridViewChiTiet01.setUpdateData()
                IGridViewChiTiet02.setUpdateData()
                IGridViewChiTiet03.setUpdateData()
                IGridViewChiTiet04.setUpdateData()
                IGridViewChiTiet05.setUpdateData()
                IGridViewChiTiet06.setUpdateData()
                If Not IsNothing(bd1) Then
                    Try
                        Me.bd1.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd2) Then
                    Try
                        Me.bd2.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd3) Then
                    Try
                        Me.bd3.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd4) Then
                    Try
                        Me.bd4.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd5) Then
                    Try
                        Me.bd5.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If Not IsNothing(bd6) Then
                    Try
                        Me.bd6.EndEdit()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message)
                    End Try
                End If
                If getSave() And state <> 0 Then
                    Me.Dispose()
                    Me.Close()
                End If
            End If
        Else
            e.Cancel = True
        End If
    End Sub
    Public Sub setAppearanceSearchLookupEdit(ByVal lc As LayoutControl)
        For Each item In lc.Items
            If TypeOf item Is LayoutControlItem Then
                Dim ct As Control = DirectCast(item, LayoutControlItem).Control
                If TypeOf ct Is BaseEdit Then
                    If TypeOf ct Is ISearchLookupEdit Then
                        DirectCast(ct, ISearchLookupEdit).Properties.View.IndicatorWidth = 55
                        DirectCast(ct, ISearchLookupEdit).Properties.View.OptionsView.EnableAppearanceEvenRow = True
                        DirectCast(ct, ISearchLookupEdit).Properties.View.Appearance.EvenRow.BackColor = Color.LightCyan
                        'DirectCast(ct, ISearchLookupEdit).Properties.NullText = "[Chọn]"
                        Me.view = CType(ct, SearchLookUpEdit).Properties.View
                        If setFormSizeSLE(CType(ct, SearchLookUpEdit).Properties.View) Then
                            DirectCast(ct, ISearchLookupEdit).Properties.PopupFormSize = New Size(800, 800)
                        End If
                        AddHandler view.CustomDrawRowIndicator, AddressOf view_CustomDrawRowIndicator
                        ''set popupformsize
                        'If view.Columns.Count >= 3 Then
                        '    DirectCast(ct, ISearchLookupEdit).Properties.PopupFormSize = New Size(800, 800)
                        'End If
                    End If
                End If
            End If
        Next
    End Sub
    'set formsize của searchlookupedit 
    Private Function setFormSizeSLE(ByVal view As GridView) As Boolean
        Dim acc As Integer = 0
        For index = 0 To view.Columns.Count - 1
            If view.Columns(index).Visible = True Then
                acc = acc + 1
            End If
        Next
        If acc >= 3 Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Sub setAppearanceSearchLookupEdit(ByVal ps As PersistentRepository)
        For Each item In ps.Items
            If TypeOf item Is RepositoryItemISearchLookUpEdit Then
                DirectCast(item, RepositoryItemISearchLookUpEdit).View.IndicatorWidth = 55
                DirectCast(item, RepositoryItemISearchLookUpEdit).View.OptionsView.EnableAppearanceEvenRow = True
                DirectCast(item, RepositoryItemISearchLookUpEdit).View.Appearance.EvenRow.BackColor = Color.LightCyan
                DirectCast(item, RepositoryItemISearchLookUpEdit).NullText = "[Chọn]"
                CType(item, RepositoryItemISearchLookUpEdit).View.OptionsFind.FindDelay = 100
                Me.view = CType(item, RepositoryItemISearchLookUpEdit).View
                If setFormSizeSLE(view) Then
                    DirectCast(item, RepositoryItemISearchLookUpEdit).PopupFormSize = New Size(800, 800)
                End If
                AddHandler view.CustomDrawRowIndicator, AddressOf view_CustomDrawRowIndicator
            End If
            If TypeOf item Is RepositoryItemIGridLookUpEdit Then
                DirectCast(item, RepositoryItemIGridLookUpEdit).View.OptionsBehavior.Editable = True
                DirectCast(item, RepositoryItemIGridLookUpEdit).View.IndicatorWidth = 55
                DirectCast(item, RepositoryItemIGridLookUpEdit).View.OptionsView.EnableAppearanceEvenRow = True
                DirectCast(item, RepositoryItemIGridLookUpEdit).View.Appearance.EvenRow.BackColor = Color.LightCyan
                DirectCast(item, RepositoryItemIGridLookUpEdit).NullText = "[Chọn]"
                CType(item, RepositoryItemIGridLookUpEdit).View.OptionsFind.FindDelay = 100
                DirectCast(item, RepositoryItemIGridLookUpEdit).TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard
                'Me.view = CType(item, RepositoryItemIGridLookUpEdit).View
                Me.view = DirectCast(item, RepositoryItemIGridLookUpEdit).View
                'DirectCast(item, RepositoryItemIGridLookUpEdit).GridSelection = New GridCheckMarksSelection(DirectCast(item, RepositoryItemIGridLookUpEdit).View)
                'Me.view = New GridCheckMarksSelection(DirectCast(item, RepositoryItemIGridLookUpEdit).View).View
                'selection_Renamed = New GridCheckMarksSelection(DirectCast(item, RepositoryItemIGridLookUpEdit).View)
                'selection_Renamed.CheckMarkColumn.VisibleIndex = 0
                AddHandler view.MouseDown, AddressOf View_MouseDown
                AddHandler view.CustomDrawRowIndicator, AddressOf view_CustomDrawRowIndicator
            End If
        Next
    End Sub
    Private Sub setFilterConditionColumns(ByVal grid As GridView)
        If grid.Columns.Count > 0 Then
            For index = 0 To grid.Columns.Count - 1
                grid.Columns(index).OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains
            Next
        End If
    End Sub
    'Private Sub loadColumnCheck()
    '    If flagCheckChiTiet01 = False Then
    '        Me.IGridViewChiTiet01.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckChiTiet02 = False Then
    '        Me.IGridViewChiTiet02.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckChiTiet03 = False Then
    '        Me.IGridViewChiTiet03.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckChiTiet04 = False Then
    '        Me.IGridViewChiTiet04.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckChiTiet05 = False Then
    '        Me.IGridViewChiTiet05.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckChiTiet06 = False Then
    '        Me.IGridViewChiTiet06.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs01 = False Then
    '        Me.IGridViewDs01.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs02 = False Then
    '        Me.IGridViewDs02.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs03 = False Then
    '        Me.IGridViewDs03.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs04 = False Then
    '        Me.IGridViewDs04.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs05 = False Then
    '        Me.IGridViewDs05.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs06 = False Then
    '        Me.IGridViewDs06.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckDs07 = False Then
    '        Me.IGridViewDs07.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckThamChieu01 = False Then
    '        Me.IGridViewDsThamChieu1.Columns("Mark").Visible = False
    '    End If
    '    If flagCheckThamChieu02 = False Then
    '        Me.IGridViewDsThamChieu2.Columns("Mark").Visible = False
    '    End If
    'End Sub
    ''' <summary>
    ''' Phân quyền cho form
    ''' </summary>
    ''' <param name="tạo_mới">quyền tạo mới</param>
    ''' <param name="sửa">quyền sửa</param>
    ''' <param name="xóa">quyền xóa</param>
    ''' <remarks></remarks>
    Public Sub setPhanQuyen(ByVal tạo_mới As Boolean, ByVal sửa As Boolean, ByVal xóa As Boolean)
        Me.m_TaoMoi = tạo_mới
        Me.m_Sua = sửa
        Me.m_Xoa = xóa
        If tạo_mới = False Then
            Me.BarButtonGroupTaoMoi.Enabled = False
            Me.BarButtonItemTaoMoi.Enabled = False
            Me.BarStaticItemTaoMoi.Enabled = False
        Else
            Me.BarButtonGroupTaoMoi.Enabled = True
            Me.BarButtonItemTaoMoi.Enabled = True
            Me.BarStaticItemTaoMoi.Enabled = True
        End If
        If sửa = False Then
            Me.BarButtonItemSua.Enabled = False
            Me.BarButtonGroupSua.Enabled = False
            Me.BarStaticItemSua.Enabled = False
        Else
            Me.BarButtonItemSua.Enabled = True
            Me.BarButtonGroupSua.Enabled = True
            Me.BarStaticItemSua.Enabled = True
        End If
        If xóa = False Then
            Me.BarButtonItemXoa.Enabled = False
            Me.BarButtonGroupXoa.Enabled = False
            Me.BarStaticItemXoa.Enabled = False
        Else
            Me.BarButtonItemXoa.Enabled = True
            Me.BarButtonGroupXoa.Enabled = True
            Me.BarStaticItemXoa.Enabled = True
        End If
        Me.RibbonControl.Refresh()
    End Sub

    Private Sub FormDon1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        setReadonlyTag(Me.LayoutControl1)
        setReadonlyControl(True)
        setAppearanceSearchLookupEdit(Me.PersistentRepository1)
        setAppearanceSearchLookupEdit(Me.LayoutControl1)
        setAppearanceSearchLookupEdit(Me.LayoutControl2)
        setFilterConditionColumns(IGridViewDs01)
        setFilterConditionColumns(IGridViewDs02)
        setFilterConditionColumns(IGridViewDs03)
        setFilterConditionColumns(IGridViewDs04)
        setFilterConditionColumns(IGridViewDs05)
        setFilterConditionColumns(IGridViewDs06)
        setFilterConditionColumns(IGridViewDs07)
        setFilterConditionColumns(IGridViewChiTiet01)
        setFilterConditionColumns(IGridViewChiTiet02)
        setFilterConditionColumns(IGridViewChiTiet03)
        setFilterConditionColumns(IGridViewChiTiet04)
        setFilterConditionColumns(IGridViewChiTiet05)
        setFilterConditionColumns(IGridViewChiTiet06)
        setFilterConditionColumns(Me.IGridViewPopUp1)
        setFilterConditionColumns(Me.IGridViewPopUp2)

        setFilterConditionColumns(Me.IGridViewDsThamChieu1)
        setFilterConditionColumns(IGridViewDsThamChieu2)
        setFilterConditionColumns(IGridViewDsThamChieu3)
        setFilterConditionColumns(IGridViewDsThamChieu4)
        setFilterConditionColumns(IGridViewDsThamChieu5)
        ''''''''''''''''''''''''''''''''''''''''
        Me.setChonTab_ChiTiet01()
        Me.setChonTab_Ds01()
        'loadColumnCheck()
        'AddHandler Me.IGridViewPopUp1.MouseDown, AddressOf View_MouseDown
        'AddHandler Me.IGridViewPopUp2.MouseDown, AddressOf View_MouseDown
    End Sub

    Private Sub BarButtonItemTaoMoiChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemTaoMoiChiTiet.ItemClick, BarButtonGroupTaoMoiChiTiet.ItemClick, BarStaticItemTaoMoiChiTiet.ItemClick
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                Me.postEditor_EndEdit()
                Me.IGridViewChiTiet01.setFocusDongDauTien()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                postEditor_EndEdit()
                Me.IGridViewChiTiet02.setFocusDongDauTien()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                postEditor_EndEdit()
                Me.IGridViewChiTiet03.setFocusDongDauTien()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                postEditor_EndEdit()
                Me.IGridViewChiTiet04.setFocusDongDauTien()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                postEditor_EndEdit()
                Me.IGridViewChiTiet05.setFocusDongDauTien()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                postEditor_EndEdit()
                Me.IGridViewChiTiet06.setFocusDongDauTien()
            End If
        End If
    End Sub
    ''' <summary>
    ''' lấy số tab sử dụng trong form
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getSoTab_SuDung() As Integer
        Return SoTab
    End Function
    ''' <summary>
    ''' lấy số tab tham chiếu sử dụng trong form
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function getSoTab_ThamChieu() As Integer
        Return SoTabThamChieu
    End Function
    ''' <summary>
    ''' Qui định số lượng tab tham chiếu sử dụng 
    ''' </summary>
    ''' <param name="số_tab_tham_chiếu_sử_dụng">số lượng tab tham chiếu</param>
    ''' <remarks></remarks>
    Public Sub setSoTabThamChieu(ByVal số_tab_tham_chiếu_sử_dụng As Integer)
        Me.SoTabThamChieu = số_tab_tham_chiếu_sử_dụng
        If Me.SoTabThamChieu = 0 Then
            Me.LayoutControlGroupDsThamChieu1.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu2.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu3.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu4.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu5.HideToCustomization()
        End If
        If Me.SoTabThamChieu = 1 Then
            Me.LayoutControlGroupDsThamChieu2.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu3.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu4.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu5.HideToCustomization()
        End If
        If Me.SoTabThamChieu = 2 Then
            Me.LayoutControlGroupDsThamChieu3.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu4.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu5.HideToCustomization()
        End If
        If Me.SoTabThamChieu = 3 Then
            Me.LayoutControlGroupDsThamChieu4.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu5.HideToCustomization()
        End If
        If Me.SoTabThamChieu = 4 Then
            Me.LayoutControlGroupDsThamChieu5.HideToCustomization()
        End If
    End Sub
    Public Sub setSoTab(ByVal số_tab_sử_dụng As Integer)
        'Me.SoTabThamChieu = số_tab_tham_chiếu
        Me.SoTab = số_tab_sử_dụng
        'Me.TabbedControlGroupChiTiet.TabPages(1).HideToCustomization()
        If Me.SoTabThamChieu = 0 Then
            Me.LayoutControlGroupDsThamChieu1.HideToCustomization()
            Me.LayoutControlGroupDsThamChieu2.HideToCustomization()
        End If
        If SoTab = 1 Then
            Me.LayoutControlGroup02.HideToCustomization()
            Me.LayoutControlGroup03.HideToCustomization()
            Me.LayoutControlGroup04.HideToCustomization()
            Me.LayoutControlGroup05.HideToCustomization()
            Me.LayoutControlGroup06.HideToCustomization()
            Me.LayoutControlGroupDs3.HideToCustomization()
            Me.LayoutControlGroupDs4.HideToCustomization()
            Me.LayoutControlGroupDs5.HideToCustomization()
            Me.LayoutControlGroupDs6.HideToCustomization()
            Me.LayoutControlGroupDs7.HideToCustomization()
        End If
        If SoTab = 2 Then
            Me.LayoutControlGroup03.HideToCustomization()
            Me.LayoutControlGroup04.HideToCustomization()
            Me.LayoutControlGroup05.HideToCustomization()
            Me.LayoutControlGroup06.HideToCustomization()
            Me.LayoutControlGroupDs4.HideToCustomization()
            Me.LayoutControlGroupDs5.HideToCustomization()
            Me.LayoutControlGroupDs6.HideToCustomization()
            Me.LayoutControlGroupDs7.HideToCustomization()
        End If
        If SoTab = 3 Then
            Me.LayoutControlGroup04.HideToCustomization()
            Me.LayoutControlGroup05.HideToCustomization()
            Me.LayoutControlGroup06.HideToCustomization()
            Me.LayoutControlGroupDs5.HideToCustomization()
            Me.LayoutControlGroupDs6.HideToCustomization()
            Me.LayoutControlGroupDs7.HideToCustomization()
        End If
        If SoTab = 4 Then
            Me.LayoutControlGroup05.HideToCustomization()
            Me.LayoutControlGroup06.HideToCustomization()
            Me.LayoutControlGroupDs6.HideToCustomization()
            Me.LayoutControlGroupDs7.HideToCustomization()
        End If
        If SoTab = 5 Then
            Me.LayoutControlGroup06.HideToCustomization()
            Me.LayoutControlGroupDs7.HideToCustomization()
        End If
    End Sub
    Public Function getState() As Integer
        Return state
    End Function

    Private Sub BarButtonItemXoaChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemXoaChiTiet.ItemClick, BarButtonGroupXoaChiTiet.ItemClick, BarStaticItemXoaChiTiet.ItemClick
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng chi tiết đang chọn không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.IGridViewChiTiet01.DeleteRow(Me.IGridViewChiTiet01.FocusedRowHandle)
                    Me.IGridViewChiTiet01.UpdateCurrentRow()
                    Me.IGridViewChiTiet01.UpdateGroupSummary()
                    Me.IGridViewChiTiet01.UpdateSummary()
                End If
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng chi tiết đang chọn không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.IGridViewChiTiet02.DeleteRow(Me.IGridViewChiTiet02.FocusedRowHandle)
                    Me.IGridViewChiTiet02.UpdateCurrentRow()
                    Me.IGridViewChiTiet02.UpdateGroupSummary()
                    Me.IGridViewChiTiet02.UpdateSummary()
                End If
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng chi tiết đang chọn không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.IGridViewChiTiet03.DeleteRow(Me.IGridViewChiTiet03.FocusedRowHandle)
                    Me.IGridViewChiTiet03.UpdateCurrentRow()
                    Me.IGridViewChiTiet03.UpdateGroupSummary()
                    Me.IGridViewChiTiet03.UpdateSummary()
                End If
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng chi tiết đang chọn không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.IGridViewChiTiet04.DeleteRow(Me.IGridViewChiTiet04.FocusedRowHandle)
                    Me.IGridViewChiTiet04.UpdateCurrentRow()
                    Me.IGridViewChiTiet04.UpdateGroupSummary()
                    Me.IGridViewChiTiet04.UpdateSummary()
                End If
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng chi tiết đang chọn không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.IGridViewChiTiet05.DeleteRow(Me.IGridViewChiTiet05.FocusedRowHandle)
                    Me.IGridViewChiTiet05.UpdateCurrentRow()
                    Me.IGridViewChiTiet05.UpdateGroupSummary()
                    Me.IGridViewChiTiet05.UpdateSummary()
                End If
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn xóa dòng chi tiết đang chọn không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                    Me.IGridViewChiTiet06.DeleteRow(Me.IGridViewChiTiet06.FocusedRowHandle)
                    Me.IGridViewChiTiet06.UpdateCurrentRow()
                    Me.IGridViewChiTiet06.UpdateGroupSummary()
                    Me.IGridViewChiTiet06.UpdateSummary()
                End If
            End If
        End If
    End Sub
    ''' <summary>
    ''' post editor và endedit bindingsource
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub postEditor_EndEdit()
        If setPostEditor(Me.LayoutControl1) Then
            Me.bd.EndEdit()
            Me.BdEndEdit()
        End If
    End Sub
    Private Sub controlLast_KeyDown(sender As Object, e As KeyEventArgs)
        Try
            If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Tab) And state <> 0 Then
                'set dropdown 
                Me.IGridViewChiTiet01.setFlagDropDown(False)
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
                    If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                        IGridViewChiTiet01.setUpdateData()
                        postEditor_EndEdit()
                        IGridViewChiTiet01.setFocusDongDauTien()
                    End If
                End If
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
                    If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                        IGridViewChiTiet02.setUpdateData()
                        postEditor_EndEdit()
                        IGridViewChiTiet02.setFocusDongDauTien()
                    End If
                End If
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
                    If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                        IGridViewChiTiet03.setUpdateData()
                        postEditor_EndEdit()
                        IGridViewChiTiet03.setFocusDongDauTien()
                    End If
                End If
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
                    If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                        IGridViewChiTiet04.setUpdateData()
                        postEditor_EndEdit()
                        IGridViewChiTiet04.setFocusDongDauTien()
                    End If
                End If
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
                    If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                        IGridViewChiTiet05.setUpdateData()
                        postEditor_EndEdit()
                        IGridViewChiTiet05.setFocusDongDauTien()
                    End If
                End If
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
                    If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                        IGridViewChiTiet06.setUpdateData()
                        postEditor_EndEdit()
                        IGridViewChiTiet06.setFocusDongDauTien()
                    End If
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BarButtonItemHuyThayDoiChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemHuyThayDoiChiTiet.ItemClick, BarButtonGroupHuyThayDoiChiTiet.ItemClick, BarStaticItemHuyThayDoiChiTiet.ItemClick
        Dim tenTab As String = Nothing
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                tenTab = LayoutControlGroup01.Text
                IGridViewChiTiet01.setUpdateData()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                tenTab = LayoutControlGroup02.Text
                IGridViewChiTiet02.setUpdateData()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                tenTab = LayoutControlGroup03.Text
                IGridViewChiTiet03.setUpdateData()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                tenTab = LayoutControlGroup04.Text
                IGridViewChiTiet04.setUpdateData()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                tenTab = LayoutControlGroup05.Text
                IGridViewChiTiet05.setUpdateData()
            End If
        End If
        If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                tenTab = LayoutControlGroup06.Text
                IGridViewChiTiet06.setUpdateData()
            End If
        End If
        If Not IsNothing(bd1) Then
            Try
                Me.bd1.EndEdit()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        If Not IsNothing(bd2) Then
            Try
                Me.bd2.EndEdit()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        If Not IsNothing(bd3) Then
            Try
                Me.bd3.EndEdit()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        If Not IsNothing(bd4) Then
            Try
                Me.bd4.EndEdit()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        If Not IsNothing(bd5) Then
            Try
                Me.bd5.EndEdit()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        If Not IsNothing(bd6) Then
            Try
                Me.bd6.EndEdit()
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End If
        If Me.ds.HasChanges Then
            If DevExpress.XtraEditors.XtraMessageBox.Show("Bạn có muốn hủy tất cả những thay đổi đang xảy ra ở '" & tenTab & "'  không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
                Me.ds.RejectChanges()
            End If
        Else
            DevExpress.XtraEditors.XtraMessageBox.Show("Chưa có thay đổi dữ liệu xảy ra ở '" & tenTab & "' !!!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Private Sub BarButtonItemFirstChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirstChiTiet.ItemClick
        Try
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd1.MoveFirst()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd2.MoveFirst()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd3.MoveFirst()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd4.MoveFirst()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd5.MoveFirst()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd6.MoveFirst()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BarButtonItemPreviousChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPreviousChiTiet.ItemClick
        Try
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd1.MovePrevious()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd2.MovePrevious()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd3.MovePrevious()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd4.MovePrevious()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd5.MovePrevious()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd6.MovePrevious()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BarButtonItemNextChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNextChiTiet.ItemClick
        Try
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd1.MoveNext()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd2.MoveNext()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd3.MoveNext()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd4.MoveNext()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd5.MoveNext()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd6.MoveNext()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub BarButtonItemLastChiTiet_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLastChiTiet.ItemClick
        Try
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 0 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd1.MoveLast()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 1 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd2.MoveLast()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 2 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd3.MoveLast()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 3 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd4.MoveLast()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 4 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd5.MoveLast()
                End If
            End If
            If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex = 5 Then
                If Me.TabbedControlGroupChiTiet.SelectedTabPageIndex <= (Me.SoTab - 1) Then
                    bd6.MoveLast()
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub IGridViewDs02_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridViewDs02.FocusedRowChanged
        Try
            Dim ma As String = Me.IGridViewDs02.GroupedColumns.View.GroupedColumns.Item(0).FieldName.ToString
            Me.bd.Position = Me.bd.Find(ma, Me.IGridViewDs02.GetGroupRowValue(Me.IGridViewDs02.FocusedRowHandle))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    'Private flagCheckDs01, flagCheckDs02, flagCheckDs03, flagCheckDs04, flagCheckDs05, flagCheckDs06, flagCheckDs07, flagCheckChiTiet01, flagCheckChiTiet02, flagCheckChiTiet03, flagCheckChiTiet04, flagCheckChiTiet05, flagCheckChiTiet06, flagCheckThamChieu01, flagCheckThamChieu02 As Boolean
    'Public Sub setColumnCheck_Ds01()
    '    Me.flagCheckDs01 = True
    'End Sub
    'Public Sub setColumnCheck_Ds02()
    '    Me.flagCheckDs02 = True
    'End Sub
    'Public Sub setColumnCheck_Ds03()
    '    Me.flagCheckDs03 = True
    'End Sub
    'Public Sub setColumnCheck_Ds04()
    '    Me.flagCheckDs04 = True
    'End Sub
    'Public Sub setColumnCheck_Ds05()
    '    Me.flagCheckDs05 = True
    'End Sub
    'Public Sub setColumnCheck_Ds06()
    '    Me.flagCheckDs06 = True
    'End Sub
    'Public Sub setColumnCheck_Ds07()
    '    Me.flagCheckDs07 = True
    'End Sub
    'Public Sub setColumnCheck_ThamChieu01()
    '    Me.flagCheckThamChieu01 = True
    'End Sub
    'Public Sub setColumnCheck_ThamChieu02()
    '    Me.flagCheckThamChieu02 = True
    'End Sub
    'Public Sub setColumnCheck_ChiTiet01()
    '    Me.flagCheckChiTiet01 = True
    'End Sub
    'Public Sub setColumnCheck_ChiTiet02()
    '    Me.flagCheckChiTiet02 = True
    'End Sub
    'Public Sub setColumnCheck_ChiTiet03()
    '    Me.flagCheckChiTiet03 = True
    'End Sub
    'Public Sub setColumnCheck_ChiTiet04()
    '    Me.flagCheckChiTiet04 = True
    'End Sub
    'Public Sub setColumnCheck_ChiTiet05()
    '    Me.flagCheckChiTiet05 = True
    'End Sub
    'Public Sub setColumnCheck_ChiTiet06()
    '    Me.flagCheckChiTiet06 = True
    'End Sub
    Public Sub New()
        InitializeComponent()
        'ht = New Hashtable
        ht1 = New Hashtable
        ht2 = New Hashtable
        ht3 = New Hashtable
        ht4 = New Hashtable
        ht5 = New Hashtable
        ht6 = New Hashtable
        htControlValue = New Hashtable
        htEdit = New Hashtable
        Me.htEditTab1 = New Hashtable
        Me.htEditTab2 = New Hashtable
        Me.htEditTab3 = New Hashtable
        Me.htEditTab4 = New Hashtable
        Me.htEditTab5 = New Hashtable
        Me.htEditTab6 = New Hashtable
        lst1 = New ArrayList
        lst2 = New ArrayList
        lst3 = New ArrayList
        lst4 = New ArrayList
        lst5 = New ArrayList
        lst6 = New ArrayList
        htNew = New Hashtable
        lstGuidDeleted = New ArrayList
        lstGuIdDeleted_tab1 = New ArrayList
        lstGuIdDeleted_tab2 = New ArrayList
        lstGuIdDeleted_tab3 = New ArrayList
        lstGuIdDeleted_tab4 = New ArrayList
        lstGuIdDeleted_tab5 = New ArrayList
        lstGuIdDeleted_tab6 = New ArrayList
        Me.IGridControlPopUp1.ForceInitialize()
    End Sub
    Public Function getLstUidDeleted() As ArrayList
        Return lstGuidDeleted
    End Function
    Public Function getLstUidDeleted_Tab1() As ArrayList
        Return lstGuIdDeleted_tab1
    End Function
    Public Function getLstUidDeleted_Tab2() As ArrayList
        Return lstGuIdDeleted_tab2
    End Function
    Public Function getLstUidDeleted_Tab3() As ArrayList
        Return lstGuIdDeleted_tab3
    End Function
    Public Function getLstUidDeleted_Tab4() As ArrayList
        Return lstGuIdDeleted_tab4
    End Function
    Public Function getLstUidDeleted_Tab5() As ArrayList
        Return lstGuIdDeleted_tab5
    End Function
    Public Function getLstUidDeleted_Tab6() As ArrayList
        Return lstGuIdDeleted_tab6
    End Function
    Private Sub IGridViewDs03_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridViewDs03.FocusedRowChanged
        Try
            Dim ma As String = Me.IGridViewDs03.GroupedColumns.Item(0).ToString()
            Me.bd.Position = Me.bd.Find(ma, Me.IGridViewDs03.GetGroupRowValue(Me.IGridViewDs03.FocusedRowHandle))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub IGridViewDs04_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridViewDs04.FocusedRowChanged
        Try
            Dim ma As String = Me.IGridViewDs04.GroupedColumns.Item(0).ToString()
            Me.bd.Position = Me.bd.Find(ma, Me.IGridViewDs04.GetGroupRowValue(Me.IGridViewDs04.FocusedRowHandle))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub IGridViewDs05_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridViewDs05.FocusedRowChanged
        Try
            Dim ma As String = Me.IGridViewDs05.GroupedColumns.Item(0).ToString()
            Me.bd.Position = Me.bd.Find(ma, Me.IGridViewDs05.GetGroupRowValue(Me.IGridViewDs05.FocusedRowHandle))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub IGridViewDs06_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridViewDs06.FocusedRowChanged
        Try
            Dim ma As String = Me.IGridViewDs06.GroupedColumns.Item(0).ToString()
            Me.bd.Position = Me.bd.Find(ma, Me.IGridViewDs06.GetGroupRowValue(Me.IGridViewDs06.FocusedRowHandle))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub IGridViewDs07_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles IGridViewDs07.FocusedRowChanged
        Try
            Dim ma As String = Me.IGridViewDs07.GroupedColumns.Item(0).ToString()
            Me.bd.Position = Me.bd.Find(ma, Me.IGridViewDs07.GetGroupRowValue(Me.IGridViewDs07.FocusedRowHandle))
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
    ''' <summary>
    ''' kiểm tra coi cột có tồn tại trong igridview hay không ?
    ''' </summary>
    ''' <remarks></remarks>
    Private Function checkContainsColumn(ByVal igridview As IGridView, ByVal lst As ArrayList) As Boolean
        For index = 0 To lst.Count - 1
            If igridview.Columns.Contains(igridview.Columns.Item(lst.Item(index).ToString)) Then
            Else
                DevExpress.XtraEditors.XtraMessageBox.Show("Cột " & lst.Item(index).ToString & " của " & igridview.Name & " trong phương thức 'setColumnsChange... không tồn tại, bạn kiểm tra lại nhé !!! :-D ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                Return False
            End If
            Return True
        Next
    End Function
    ''' <summary>
    ''' Danh sách các cột phải tính lại giá trị khi có thay đổi xảy ra ở tab1
    ''' </summary>
    ''' <param name="lst">Danh sách chứa tên các cột ở tab1</param>
    ''' <remarks></remarks>
    Public Sub setColumnsChangeTab1(ByVal lst As ArrayList)
        If checkContainsColumn(Me.IGridViewChiTiet01, lst) Then
            Me.lst1 = lst
        End If
        'getLst1()
    End Sub
    ''' <summary>
    ''' Danh sách các cột phải tính lại giá trị khi có thay đổi xảy ra ở tab2
    ''' </summary>
    ''' <param name="lst">Danh sách chứa tên các cột ở tab2</param>
    ''' <remarks></remarks>
    Public Sub setColumnsChangeTab2(ByVal lst As ArrayList)
        If checkContainsColumn(Me.IGridViewChiTiet02, lst) Then
            Me.lst2 = lst
        End If
    End Sub
    ''' <summary>
    ''' Danh sách các cột phải tính lại giá trị khi có thay đổi xảy ra ở tab3
    ''' </summary>
    ''' <param name="lst">Danh sách chứa tên các cột ở tab3</param>
    ''' <remarks></remarks>
    Public Sub setColumnsChangeTab3(ByVal lst As ArrayList)
        If checkContainsColumn(Me.IGridViewChiTiet03, lst) Then
            Me.lst3 = lst
        End If
    End Sub
    ''' <summary>
    ''' Danh sách các cột phải tính lại giá trị khi có thay đổi xảy ra ở tab4
    ''' </summary>
    ''' <param name="lst">Danh sách chứa tên các cột ở tab4</param>
    ''' <remarks></remarks>
    Public Sub setColumnsChangeTab4(ByVal lst As ArrayList)
        If checkContainsColumn(Me.IGridViewChiTiet04, lst) Then
            Me.lst4 = lst
        End If
    End Sub
    ''' <summary>
    ''' Danh sách các cột phải tính lại giá trị khi có thay đổi xảy ra ở tab5
    ''' </summary>
    ''' <param name="lst">Danh sách chứa tên các cột ở tab5</param>
    ''' <remarks></remarks>
    Public Sub setColumnsChangeTab5(ByVal lst As ArrayList)
        If checkContainsColumn(Me.IGridViewChiTiet05, lst) Then
            Me.lst5 = lst
        End If
    End Sub
    ''' <summary>
    ''' Danh sách các cột phải tính lại giá trị khi có thay đổi xảy ra ở tab6
    ''' </summary>
    ''' <param name="lst">Danh sách chứa tên các cột ở tab6</param>
    ''' <remarks></remarks>
    Public Sub setColumnsChangeTab6(ByVal lst As ArrayList)
        If checkContainsColumn(Me.IGridViewChiTiet06, lst) Then
            Me.lst6 = lst
        End If
    End Sub
    ''' <summary>
    ''' Gán giá trị một control trên form cho một cột trong grid
    ''' (vì gán vô lưới thì mới có thể dùng expression tính toán được)
    ''' </summary>
    ''' <remarks></remarks>
    Public Overloads Sub setControlValue_IGridViewChiTiet01()
    End Sub
    ''' <summary>
    ''' Tính toán giá trị cột thông qua expression của phần chi tiết tab1
    ''' </summary>
    ''' <param name="colex">Tên cột tạm chứa express editor</param>
    ''' <param name="colthiet">Tên cột thật cần gán giá trị</param>
    ''' <remarks></remarks>
    Public Sub setColumnValueTab1(ByVal colex As GridColumn, ByVal colthiet As GridColumn)
        Me.ht1.Add(colthiet, colex)
    End Sub
    ''' <summary>
    ''' Tính toán giá trị cột thông qua expression của phần chi tiết tab2
    ''' </summary>
    ''' <param name="colex">Tên cột tạm chứa express editor</param>
    ''' <param name="colthiet">Tên cột thật cần gán giá trị</param>
    ''' <remarks></remarks>
    Public Sub setColumnValueTab2(ByVal colex As GridColumn, ByVal colthiet As GridColumn)
        Me.ht2.Add(colthiet, colex)
    End Sub
    ''' <summary>
    ''' Tính toán giá trị cột thông qua expression của phần chi tiết tab3
    ''' </summary>
    ''' <param name="colex">Tên cột tạm chứa express editor</param>
    ''' <param name="colthiet">Tên cột thật cần gán giá trị</param>
    ''' <remarks></remarks>
    Public Sub setColumnValueTab3(ByVal colex As GridColumn, ByVal colthiet As GridColumn)
        Me.ht3.Add(colthiet, colex)
    End Sub
    ''' <summary>
    ''' Tính toán giá trị cột thông qua expression của phần chi tiết tab4
    ''' </summary>
    ''' <param name="colex">Tên cột tạm chứa express editor</param>
    ''' <param name="colthiet">Tên cột thật cần gán giá trị</param>
    ''' <remarks></remarks>
    Public Sub setColumnValueTab4(ByVal colex As GridColumn, ByVal colthiet As GridColumn)
        Me.ht4.Add(colthiet, colex)
    End Sub
    ''' <summary>
    ''' Tính toán giá trị cột thông qua expression của phần chi tiết tab5
    ''' </summary>
    ''' <param name="colex">Tên cột tạm chứa express editor</param>
    ''' <param name="colthiet">Tên cột thật cần gán giá trị</param>
    ''' <remarks></remarks>
    Public Sub setColumnValueTab5(ByVal colex As GridColumn, ByVal colthiet As GridColumn)
        Me.ht5.Add(colthiet, colex)
    End Sub
    ''' <summary>
    ''' Tính toán giá trị cột thông qua expression của phần chi tiết tab6
    ''' </summary>
    ''' <param name="colex">Tên cột tạm chứa express editor</param>
    ''' <param name="colthiet">Tên cột thật cần gán giá trị</param>
    ''' <remarks></remarks>
    Public Sub setColumnValueTab6(ByVal colex As GridColumn, ByVal colthiet As GridColumn)
        Me.ht6.Add(colthiet, colex)
    End Sub
    Private Sub IGridViewDs01_InitNewRow(sender As Object, e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles IGridViewDs01.InitNewRow
        Me.controlFirst.Focus()
    End Sub

    Private Sub IGridViewChiTiet01_InitNewRow(sender As Object, e As DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs) Handles IGridViewChiTiet01.InitNewRow
        Me.flagInitNewRow1 = False
    End Sub
    ''' <summary>
    ''' set trạng thái cho form (dùng khi ở lớp con set ngược lên trạng thái của lớp cha)
    ''' </summary>
    ''' <param name="state">Trạng thái</param>
    ''' <remarks></remarks>
    Public Sub setState(ByVal state As Integer)
        Me.state = state
    End Sub
    Private Sub BarButtonItemThoatPopUp1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoatPopUp1.ItemClick
        Me.PopupContainerControl1.OwnerEdit.ClosePopup()
    End Sub
    Private Sub BarButtonItemThoatPopUp2_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemThoatPopUp2.ItemClick
        Me.PopupContainerControl2.OwnerEdit.ClosePopup()
    End Sub
    Private Sub BarButtonItemFirstPopUp2_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemFirstPopUp2.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp2.MoveFirst()
        End If
    End Sub
    Private Sub BarButtonItemPreviousPopUp2_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPreviousPopUp2.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp2.MovePrevious()
        End If
    End Sub
    Private Sub BarButtonItemNextPopUp2_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNextPopUp2.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp2.MoveNext()
        End If
    End Sub
    Private Sub BarButtonItemLastPopUp2_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLastPopUp2.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp2.MoveLast()
        End If
    End Sub
    Private Sub BarButtonItemDauPopUp1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemDauPopUp1.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp1.MoveFirst()
        End If
    End Sub
    Private Sub BarButtonItemPreviousPopUp1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemPreviousPopUp1.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp1.MovePrevious()
        End If
    End Sub
    Private Sub BarButtonItemNextPopUp1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemNextPopUp1.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp1.MoveNext()
        End If
    End Sub
    Private Sub BarButtonItemLastPopUp1_ItemClick(sender As System.Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItemLastPopUp1.ItemClick
        If bdPopUp2 IsNot Nothing Then
            Me.bdPopUp1.MoveLast()
        End If
    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
    End Sub
    Private Sub IGridViewChiTiet01_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridViewChiTiet01.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        Dim Item As DictionaryEntry
        For Each Item In ht1
            If (lst1.Contains(e.Column.FieldName.ToString)) AndAlso (Not flag1) AndAlso IsDBNull(e.Value) = False AndAlso flagInitNewRow1 = True Then
                Me.flag1 = True
                'set controlValue
                setControlValue_IGridViewChiTiet01()
                'end set controlValue
                If IsNothing(Me.IGridViewChiTiet01.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName)) Then
                    'MessageBox.Show(CType(Item.Value, GridColumn).FieldName.ToString)
                Else
                    view1.SetRowCellValue(e.RowHandle, CType(Item.Key, GridColumn).FieldName, Me.IGridViewChiTiet01.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName))
                    view1.UpdateSummary()
                    view1.UpdateTotalSummary()
                    view1.UpdateCurrentRow()
                    view1.UpdateGroupSummary()
                End If
                Me.flag1 = False
            End If
        Next
    End Sub
    Private Sub IGridViewChiTiet02_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridViewChiTiet02.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        Dim Item As DictionaryEntry
        For Each Item In ht2
            If (lst2.Contains(e.Column.FieldName.ToString)) AndAlso (Not flag2) AndAlso IsDBNull(e.Value) = False AndAlso flagInitNewRow2 = True Then
                Me.flag2 = True
                'set controlValue
                'setControlValue_IGridViewChiTiet01()
                'end set controlValue
                If IsNothing(Me.IGridViewChiTiet02.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName)) Then
                    'MessageBox.Show(CType(Item.Value, GridColumn).FieldName.ToString)
                Else
                    view1.SetRowCellValue(e.RowHandle, CType(Item.Key, GridColumn).FieldName, Me.IGridViewChiTiet02.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName))
                    view1.UpdateSummary()
                    view1.UpdateTotalSummary()
                    view1.UpdateCurrentRow()
                    view1.UpdateGroupSummary()
                    Me.flag2 = False
                End If
            End If
        Next
    End Sub

    Private Sub IGridViewChiTiet03_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridViewChiTiet03.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        Dim Item As DictionaryEntry
        For Each Item In ht3
            If (lst3.Contains(e.Column.FieldName.ToString)) AndAlso (Not flag3) AndAlso IsDBNull(e.Value) = False AndAlso flagInitNewRow3 = True Then
                Me.flag3 = True
                'set controlValue
                'setControlValue_IGridViewChiTiet01()
                'end set controlValue
                view1.SetRowCellValue(e.RowHandle, CType(Item.Key, GridColumn).FieldName, Me.IGridViewChiTiet03.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName))
                view1.UpdateSummary()
                view1.UpdateTotalSummary()
                view1.UpdateCurrentRow()
                view1.UpdateGroupSummary()
                Me.flag3 = False
            End If
        Next
    End Sub

    Private Sub IGridViewChiTiet04_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridViewChiTiet04.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        Dim Item As DictionaryEntry
        For Each Item In ht4
            If (lst4.Contains(e.Column.FieldName.ToString)) AndAlso (Not flag4) AndAlso IsDBNull(e.Value) = False AndAlso flagInitNewRow4 = True Then
                Me.flag4 = True
                'set controlValue
                'setControlValue_IGridViewChiTiet01()
                'end set controlValue
                view1.SetRowCellValue(e.RowHandle, CType(Item.Key, GridColumn).FieldName, Me.IGridViewChiTiet04.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName))
                view1.UpdateSummary()
                view1.UpdateTotalSummary()
                view1.UpdateCurrentRow()
                view1.UpdateGroupSummary()
                Me.flag4 = False
            End If
        Next
    End Sub

    Private Sub IGridViewChiTiet05_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridViewChiTiet05.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        Dim Item As DictionaryEntry
        For Each Item In ht5
            If (lst5.Contains(e.Column.FieldName.ToString)) AndAlso (Not flag5) AndAlso IsDBNull(e.Value) = False AndAlso flagInitNewRow5 = True Then
                Me.flag5 = True
                'set controlValue
                setControlValue_IGridViewChiTiet01()
                'end set controlValue
                view1.SetRowCellValue(e.RowHandle, CType(Item.Key, GridColumn).FieldName, Me.IGridViewChiTiet05.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName))
                view1.UpdateSummary()
                view1.UpdateTotalSummary()
                view1.UpdateCurrentRow()
                view1.UpdateGroupSummary()
                Me.flag5 = False
            End If
        Next
    End Sub

    Private Sub IGridViewChiTiet06_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles IGridViewChiTiet06.CellValueChanged
        Dim view1 As GridView = CType(sender, GridView)
        Dim Item As DictionaryEntry
        For Each Item In ht6
            If (lst6.Contains(e.Column.FieldName.ToString)) AndAlso (Not flag6) AndAlso IsDBNull(e.Value) = False AndAlso flagInitNewRow6 = True Then
                Me.flag6 = True
                'set controlValue
                setControlValue_IGridViewChiTiet01()
                'end set controlValue
                view1.SetRowCellValue(e.RowHandle, CType(Item.Key, GridColumn).FieldName, Me.IGridViewChiTiet06.GetFocusedRowCellValue(CType(Item.Value, GridColumn).FieldName))
                view1.UpdateSummary()
                view1.UpdateTotalSummary()
                view1.UpdateCurrentRow()
                view1.UpdateGroupSummary()
                Me.flag6 = False
            End If
        Next
    End Sub

    Private Sub PrintableComponentLink1_CreateReportHeaderArea(sender As Object, e As DevExpress.XtraPrinting.CreateAreaEventArgs) Handles PrintableComponentLink1.CreateReportHeaderArea
        Dim brick As DevExpress.XtraPrinting.TextBrick
        brick = e.Graph.DrawString("My Report", Color.Navy, New RectangleF(0, 0, 500, 40), DevExpress.XtraPrinting.BorderSide.None)
        brick.Font = New Font("Tahoma", 16)
        brick.StringFormat = New DevExpress.XtraPrinting.BrickStringFormat(StringAlignment.Center)
    End Sub

    Private Sub IGridViewChiTiet02_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles IGridViewChiTiet02.InitNewRow
        Me.flagInitNewRow2 = False
    End Sub

    Private Sub IGridViewChiTiet03_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles IGridViewChiTiet03.InitNewRow
        Me.flagInitNewRow3 = False
    End Sub

    Private Sub IGridViewChiTiet04_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles IGridViewChiTiet04.InitNewRow
        Me.flagInitNewRow4 = False
    End Sub

    Private Sub IGridViewChiTiet05_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles IGridViewChiTiet05.InitNewRow
        Me.flagInitNewRow5 = False
    End Sub

    Private Sub IGridViewChiTiet06_InitNewRow(sender As Object, e As InitNewRowEventArgs) Handles IGridViewChiTiet06.InitNewRow
        Me.flagInitNewRow6 = False
    End Sub

    Private Sub BarButtonGroupBaoCao_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonGroupBaoCao.ItemClick
        Me.BarButtonItemBaoCao.PerformClick()
    End Sub
    Private Sub BarStaticItemBaoCao_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarStaticItemBaoCao.ItemClick
        Me.BarButtonItemBaoCao.PerformClick()
    End Sub

    Private Sub IGridViewChiTiet01_RowClick(sender As Object, e As RowClickEventArgs) Handles IGridViewChiTiet01.RowClick
        If Me.getState <> 0 Then
            'Me.igridview.setUpdateData()
            bd.EndEdit()
            ' iGridSetUpdateData() 'update lưới
            BdEndEdit() 'end edit các tab
        End If
    End Sub
    '======================== CHI TIẾT ========================================================
    ''' <summary>
    ''' Chọn tab chi tiết 01 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab chi tiết 01 thì mới xử lý trên igridviewchitiet01 được </remarks>
    Public Sub setChonTab_ChiTiet01()
        Me.TabbedControlGroupChiTiet.SelectedTabPage = Me.LayoutControlGroup01
    End Sub
    ''' <summary>
    ''' Chọn tab chi tiết 01 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab chi tiết 02 thì mới xử lý trên igridviewchitiet02 được </remarks>
    Public Sub setChonTab_ChiTiet02()
        Me.TabbedControlGroupChiTiet.SelectedTabPage = Me.LayoutControlGroup02
    End Sub
    ''' <summary>
    ''' Chọn tab chi tiết 03 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab chi tiết 03 thì mới xử lý trên igridviewchitiet03 được </remarks>
    Public Sub setChonTab_ChiTiet03()
        Me.TabbedControlGroupChiTiet.SelectedTabPage = Me.LayoutControlGroup03
    End Sub
    ''' <summary>
    ''' Chọn tab chi tiết 04 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab chi tiết 04 thì mới xử lý trên igridviewchitiet04 được </remarks>
    Public Sub setChonTab_ChiTiet04()
        Me.TabbedControlGroupChiTiet.SelectedTabPage = Me.LayoutControlGroup04
    End Sub
    ''' <summary>
    ''' Chọn tab chi tiết 05 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab chi tiết 05 thì mới xử lý trên igridviewchitiet05 được </remarks>
    Public Sub setChonTab_ChiTiet05()
        Me.TabbedControlGroupChiTiet.SelectedTabPage = Me.LayoutControlGroup05
    End Sub
    ''' <summary>
    ''' Chọn tab chi tiết 06 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab chi tiết 06 thì mới xử lý trên igridviewchitiet06 được </remarks>
    Public Sub setChonTab_ChiTiet06()
        Me.TabbedControlGroupChiTiet.SelectedTabPage = Me.LayoutControlGroup06
    End Sub
    '======================== DANH SÁCH ========================================================
    ''' <summary>
    ''' Chọn tab danh sách 01 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 01 thì mới xử lý trên IGridViewDs01 được </remarks>
    Public Sub setChonTab_Ds01()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs1
    End Sub
    ''' <summary>
    ''' Chọn tab danh sách 02 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 02 thì mới xử lý trên IGridViewDs02 được </remarks>
    Public Sub setChonTab_Ds02()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs2
    End Sub
    ''' <summary>
    ''' Chọn tab danh sách 03 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 03 thì mới xử lý trên IGridViewDs03 được </remarks>
    Public Sub setChonTab_Ds03()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs3
    End Sub
    ''' <summary>
    ''' Chọn tab danh sách 04 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 04 thì mới xử lý trên IGridViewDs04 được </remarks>
    Public Sub setChonTab_Ds04()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs4
    End Sub
    ''' <summary>
    ''' Chọn tab danh sách 05 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 05 thì mới xử lý trên IGridViewDs05 được </remarks>
    Public Sub setChonTab_Ds05()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs5
    End Sub
    ''' <summary>
    ''' Chọn tab danh sách 06 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 06 thì mới xử lý trên IGridViewDs06 được </remarks>
    Public Sub setChonTab_Ds06()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs6
    End Sub
    ''' <summary>
    ''' Chọn tab danh sách 07 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab danh sách 07 thì mới xử lý trên IGridViewDs07 được </remarks>
    Public Sub setChonTab_Ds07()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDs7
    End Sub
    '========================THAM CHIẾU ===================================
    ''' <summary>
    ''' Chọn tab tham chiếu 01 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab tham chiếu 01 thì mới xử lý trên IGridViewTC01 được </remarks>
    Public Sub setChonTab_ThamChieu01()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDsThamChieu1
    End Sub
    ''' <summary>
    ''' Chọn tab tham chiếu 02 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab tham chiếu 02 thì mới xử lý trên IGridViewDsThamChieu2 được </remarks>
    Public Sub setChonTab_ThamChieu02()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDsThamChieu2
    End Sub
    ''' <summary>
    ''' Chọn tab tham chiếu 03 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab tham chiếu 03 thì mới xử lý trên IGridViewDsThamChieu3 được </remarks>
    Public Sub setChonTab_ThamChieu03()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDsThamChieu3
    End Sub
    ''' <summary>
    ''' Chọn tab tham chiếu 04 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab tham chiếu 04 thì mới xử lý trên IGridViewDsThamChieu4 được </remarks>
    Public Sub setChonTab_ThamChieu04()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDsThamChieu4
    End Sub
    ''' <summary>
    ''' Chọn tab tham chiếu 05 để thao tác 
    ''' </summary>
    ''' <remarks>Chọn tab tham chiếu 05 thì mới xử lý trên IGridViewDsThamChieu5 được </remarks>
    Public Sub setChonTab_ThamChieu05()
        Me.TabbedControlGroupDanhSach.SelectedTabPage = Me.LayoutControlGroupDsThamChieu5
    End Sub
    ''' <summary>
    ''' Di chuyển tới dòng cuối cùng (dòng thông tin của ds01)
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub setMoveLast()
        Try
            Me.IGridControlDs01.ForceInitialize()
            Me.bd.MoveLast()
        Catch ex As Exception
            DevExpress.XtraEditors.XtraMessageBox.Show("lỗi " & ex.Message)
        End Try
    End Sub
End Class